﻿using System;
using System.Net;

namespace OAuth.Net.Consumer
{
    /// <summary>
    /// 
    /// </summary>
    public class PreSendHttpWebRequestEventArgs : EventArgs
    {

        /// <summary>
        /// 
        /// </summary>
        private HttpWebRequest _httpRequest;

        /// <summary>
        /// 
        /// </summary>
        readonly string _bodyContent = string.Empty;

        /// <summary>
        /// The request token issued by the service provider
        /// </summary>
        public string BodyContent
        {
            get
            {
                return _bodyContent;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="httpRequest"></param>
        public PreSendHttpWebRequestEventArgs(HttpWebRequest httpRequest, string bodyContent)
        {
            _httpRequest = httpRequest;
            _bodyContent = bodyContent;
        }

        /// <summary>
        /// 
        /// </summary>
        public long ContentLength
        {
            get { return _httpRequest.ContentLength; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string ContentType
        {
            get { return _httpRequest.ContentType; }
        }

        /// <summary>
        /// 
        /// </summary>
        public WebHeaderCollection Headers
        {
            get { return _httpRequest.Headers; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Method
        {
            get { return _httpRequest.Method; }
        }

        public Version ProtocolVersion
        {
            get { return _httpRequest.ProtocolVersion; }
        }

        /// <summary>
        /// 
        /// </summary>
        public Uri RequestUri
        {
            get { return _httpRequest.RequestUri; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string UserAgent
        {
            get { return _httpRequest.UserAgent; }
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }


        /// <summary>
        /// 
        /// </summary>
        private bool _alreadyDisposed;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="isDisposing"></param>
        protected virtual void Dispose(bool isDisposing)
        {
            if (_alreadyDisposed)
            {
                return;
            }

            if (isDisposing)
            {
                _httpRequest = null;
            }

            _alreadyDisposed = true;
        }
    }
}
